package com.vip;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.google.gson.Gson;


public class TyApiTest {
	public static void main(String[] args) {
		HttpRequester request = new HttpRequester();
		//userLogin(request); //用户登录
		//userGetBase(request); //获取用户资料
		//userModifyBase(request);//修改用户资料
		//userGetAlbum(request);//获取用户相册信息
		//userGetPicinfolist(request);//图片分类列表
		//userGetPicinfo(request);//单张图片信息
		//userDelPicinfo(request);// 删除图片
		//modifPic(request);//修改图片属性
		//friendsInfo(request);//获取好友列表
		//uploadImage(request);//上传
	    //getUserMes(request);//获取好友消息
		//getFriends(request);//获取好友列表
		//addFriend(request);//添加好友
		//getUserRadom(request);//随即获取好友
		getUserImage(request);//获取用户图片
		//删除用户消息
//		for(int i =0;i<4;i++){
//		System.out.println("2222");
//		int d = 0;
//		for(int j = 0 ; j<3;j++){
//			d ++;
//			System.out.println("1111");
//			if(d == 2){
//				continue;
//			}
//		}
//		System.out.println("213");
//		}
//		String rspString = "99.1".substring(0,2);
//		System.out.println(rspString);
	}
	  /** *//**
     * 文件转化为字节数组
     * @Author Sean.guo
     * @EditTime 2007-8-13 上午11:45:28
     */
    public static byte[] getBytesFromFile(File f) {
        if (f == null) {
            return null;
        }
        try {
            FileInputStream stream = new FileInputStream(f);
            ByteArrayOutputStream out = new ByteArrayOutputStream(1000);
            byte[] b = new byte[1000];
            int n;
            while ((n = stream.read(b)) != -1)
                out.write(b, 0, n);
            stream.close();
            out.close();
            return out.toByteArray();
        } catch (IOException e) {
        	e.printStackTrace();
        }
        return null;
    }
	/**
	 * 图片上传
	 * @throws Exception 
	 */
	public static void uploadImage(HttpRequester request){
//		<form name="uploadForm" action="/interface/picmanage.jsp/upload" method="post" enctype="multipart/form-data">
//		<input name="saveFilePath" value="/tmp/${passport}/">
//		<input type="file" size="35" name="pic">
//		</form>
		
		String value = "/tmp/18926128667@189.cn/";
		Map<String, String> params = new HashMap<String, String>();
		params.put("saveFilePath", value);
		String http ="http://59.36.102.177:55520/interface/picmanage.jsp/upload";
		File file = new File("D:/test4.jpg");
		FormFile formfile = new FormFile("test.jpg", getBytesFromFile(file), "file", "application/octet-stream");
		FormFile formfile2 = new FormFile("test.jpg", file, "file", "application/octet-stream");
		try {
			request.post(http, params, formfile2);
			//request.post2(http, params, formfile2);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 用户登录
	 */
	public static void userLogin(HttpRequester request){
		String http ="http://59.36.102.177:55520" +
				"/interface/usermanage.jsp/login?imsi=133001330000&passport=18926128667@189.cn&passsword=123456";
		
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userLogin:"+jsonRsp);
	}
	/**
	 * 用户资料
	 */
	public static void userGetBase(HttpRequester request){
		//18926128668@189.cn
		String http ="http://59.36.102.177:55520" +
				"/interface/usermanage.jsp/userinfo?passport=18926128668@189.cn";
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userGetBase:"+jsonRsp);
	}
	/**
	 * 修改用户资料
	 */
	public static void userModifyBase(HttpRequester request){
		String http ="http://59.36.102.177:55520" +
				"/interface/usermanage.jsp/modifuser?nickname=刘德华&passport=18926128667@189.cn&mobile=13430268383&pause=&itvid=XXX&gander=男";
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userModifyBase:"+jsonRsp);
	}
	/**
	 * 获取用户相册空间信息
	 */
	public static void userGetAlbum(HttpRequester request){
		String http ="http://59.36.102.177:55520" +
				"/interface/usermanage.jsp/album?passport=18926128667@189.cn";
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userGetAlbum:"+jsonRsp);
    	// Gson gson = new Gson();
    	//AlbumInfo info = gson.fromJson(jsonRsp.toString(), AlbumInfo.class);
    	//test test = gson.fromJson(info.getData().toString(), test.class);
    	//System.out.println("rsp userGetAlbum:"+test.getAvailable());
    	 jsonRsp = "["+jsonRsp+"]";
//		JSONArray array = new JSONArray(jsonRsp);
//    	JSONObject obj= array.getJSONObject(0);
//    	JSONObject res= obj.getJSONObject("data");
//        MyLog.info(getClass(), "jsonData:"+res.toString());
//    	info = (UserInfo)JsonUtils.parseJson2Obj(res.toString(), UserInfo.class);
	}
	/**
	 * 图片分类列表
	 */
	public static void userGetPicinfolist(HttpRequester request){
		String http ="http://59.36.102.177:55520" +
				"/interface/picmanage.jsp/picinfolist?type=4&passport=18926128667@189.cn&attribute=2";
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userGetPicinfolist:"+jsonRsp);
	}
	/**
	 * 单张图片信息
	 */
	public static void userGetPicinfo(HttpRequester request){
		String http ="http://59.36.102.177:55520" +
				"/interface/picmanage.jsp/picinfo?passport=18926128667@189.cn&picId=31";
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userGetPicinfo:"+jsonRsp);
	}
	/**
	 * 删除图片
	 */
	public static void userDelPicinfo(HttpRequester request){
		String http ="http://59.36.102.177:55520" +
				"/interface/picmanage.jsp/delpic?passport=18926128667@189.cn&picId=12";
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userGetPicinfo:"+jsonRsp);
	}
	/**
	 * 修改图片属性
	 */
	public static void modifPic(HttpRequester request){
		String http ="http://59.36.102.177:55520" +
				"/interface/picmanage.jsp/modifpic?passport=18926128667@189.cn&picId=12&type=1&attribute=2";
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userGetPicinfo:"+jsonRsp);
	}
	/**
	 * 获取好友列表
	 */
	public static void friendsInfo(HttpRequester request){
		String http ="http://59.36.102.177:55520" +
				"/interface/friendmanage.jsp/getfriendlist?passport=18926128667@189.cn&pageNO=1&pageSize=20";
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userGetPicinfo:"+jsonRsp);
	}
	/**
	 * 获取用户消息
	 */
	public static void getUserMes(HttpRequester request){
		String http ="http://59.36.102.177:55520" +
				"/interface/usermanage.jsp/qmessage?passport=18926128667@189.cn&&pageN0=1&pageSize=100";
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userGetPicinfo:"+jsonRsp);
	}
	/**
	 * 删除用户消息
	 */
	public static void delUserMes(HttpRequester request){
		String http ="http://59.36.102.177:55520" +
				"/interface/usermanage.jsp/getfriendlist?passport=18926128667@189.cn&pageNO=1&pageSize=20";
		//http://domain/usermanage.jsp/delmessage?passport=XXX&messageid=XXXX
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userGetPicinfo:"+jsonRsp);
	}
	
	/**
	 * 获取好友列表
	 */
	public static void getFriends(HttpRequester request){
		String http ="http://59.36.102.177:55520" +
				"/interface/friendmanage.jsp/getfriendlist?passport=18926128667@189.cn&pageSize=10&pageNO=1";
		// http://domian/interface/friendmanage.jsp/getfriendlist?passport=xxxx&pageSize=XXX&pageNO=XXX
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userGetPicinfo:"+jsonRsp);
	}
	/**
	 * 添加好友
	 */
	public static void addFriend(HttpRequester request){
		String http ="http://59.36.102.177:55520" +
				"/interface/friendmanage.jsp/addfriend?passport=18926128667@189.cn&username=18926128668@189.cn";
		//http://domian/interface/friendmanage.jsp/addfriend?passport=XXXX&username=XXXX
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userGetPicinfo:"+jsonRsp);
	}
	/**
	 * 随即获取用户
	 */
	public static void getUserRadom(HttpRequester request){
		String http ="http://59.36.102.177:55520" +
				"/interface/usermanage.jsp/getusers";
		//http://domain/interface/usermanage.jsp/getusers
		
		System.out.println(http);
    	String jsonRsp = request.sendDataPost(http, null);
    	System.out.println("rsp userGetPicinfo:"+jsonRsp);
	}
		 /**
			 * 随即获取用户
			 */
	public static void getUserImage(HttpRequester request){
				String http ="http://59.36.102.177:55520" +
						"/interface/picmanage.jsp/picinfolist?type=&passport=18926128667@189.cn&attribute=";
				 //http://ephoto.189.cn/interface/picmanage.jsp/picinfolist?type=4&passport=18926128667@189.cn&attribute=0
				
				System.out.println(http);
		    	String jsonRsp = request.sendDataPost(http, null);
		    	System.out.println("rsp userGetPicinfo:"+jsonRsp);
	}	 
		 
		 
}
